package com.contract.spirit.func.dialog

import android.annotation.SuppressLint
import android.content.Context
import android.widget.ImageView
import com.contract.commonlib.util.ext.setOnSingleClickListener
import com.contract.spirit.R
import com.contract.spirit.func.callback.OnPayListener
import com.contract.spirit.func.widget.PayPasswordInputView
import com.lxj.xpopup.XPopup
import com.lxj.xpopup.animator.PopupAnimator
import com.lxj.xpopup.animator.TranslateAnimator
import com.lxj.xpopup.core.CenterPopupView
import com.lxj.xpopup.enums.PopupAnimation
import com.lxj.xpopup.util.XPopupUtils

/**
 * @author: witness
 * created: 2021/9/30
 * desc:
 */
@SuppressLint("ViewConstructor")
class InputPayPasswordDialog(mContext:Context, var payListener: OnPayListener) : CenterPopupView(mContext) {
    override fun getImplLayoutId(): Int {
        return R.layout.dialog_input_pay_password
    }
    override fun onCreate() {
        super.onCreate()
        val payView: PayPasswordInputView = findViewById(R.id.payView)
        val ivClose = findViewById<ImageView>(R.id.iv_close)
        ivClose.setOnSingleClickListener { dismiss() }
        payView.setOnInputListener(object : PayPasswordInputView.OnInputListener {
            override fun onSucess(code: String) {
                //提现
                payListener.startPay(code)
            }

            override fun onInput() {}
        })
    }

    override fun getMaxWidth(): Int {
        return XPopupUtils.getAppWidth(context)
    }
    override fun getPopupAnimator(): PopupAnimator? {
        return TranslateAnimator(popupContentView,1000, PopupAnimation.TranslateFromBottom)
    }

    companion object{
        fun showDialog(mContext: Context, payListener: OnPayListener?) {
            XPopup.setShadowBgColor(mContext.resources.getColor(R.color.colorAlpha20))
            val payPasswordDialog = InputPayPasswordDialog(
                mContext,
                payListener!!
            )
            XPopup.Builder(mContext)
                .autoOpenSoftInput(true)
                .dismissOnTouchOutside(false)
                .dismissOnBackPressed(true)
                .asCustom(payPasswordDialog)
                .show()
        }
    }
}